package com.netease.nim.demo.session.model;

import com.netease.nim.demo.session.model.extension.CustomAttachment;
import com.netease.nim.demo.session.model.extension.CustomAttachmentType;
import com.netease.nimlib.sdk.msg.constant.MsgDirectionEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;

import java.io.Serializable;


public class MsgListItem
        implements
        Serializable
{
	
	private static final long serialVersionUID = -2459561887857715579L;
	
	private IMMessage         message;
	
	public boolean            needShowTime     = false;
	
	public float              progress         = 0f;
	
	public MsgListItem(IMMessage message) {
		this.message = message;
	}
	
	public IMMessage getMessage() {
		return message;
	}
	
	public int getViewHolderType() {
		boolean in = message.getDirect() == MsgDirectionEnum.In;
		switch (message.getMsgType()) {
			case text:
				return in ? MsgViewHolderType.TEXT_LEFT : MsgViewHolderType.TEXT_RIGHT;
			case image:
				return in ? MsgViewHolderType.PICTURE_LEFT : MsgViewHolderType.PICTURE_RIGHT;
			case audio:
				return in ? MsgViewHolderType.AUDIO_LEFT : MsgViewHolderType.AUDIO_RIGHT;
			case video:
				return in ? MsgViewHolderType.VIDEO_LEFT : MsgViewHolderType.VIDEO_RIGHT;
//			case location:
//				return in ? MsgViewHolderType.LOCATION_LEFT : MsgViewHolderType.LOCATION_RIGHT;
			case file:
	            return in ? MsgViewHolderType.FILE_LEFT : MsgViewHolderType.FILE_RIGHT;
			case avchat:
				return in ? MsgViewHolderType.AV_CHAT_LEFT : MsgViewHolderType.AV_CHAT_RIGHT;
			case notification:
				return MsgViewHolderType.NOTIFICATION;
			case custom: {
				CustomAttachment attachment = (CustomAttachment) message.getAttachment();
				switch (attachment.getType()) {
					case CustomAttachmentType.Guess:
						return in ? MsgViewHolderType.GUESS_LEFT : MsgViewHolderType.GUESS_RIGHT;
					case CustomAttachmentType.InteractionInfo:
						return in ? MsgViewHolderType.CUSTOM_ACTIVITY_LEFT : MsgViewHolderType.CUSTOM_ACTIVITY_RIGHT;
					default:
						return in ? MsgViewHolderType.CUSTOM_DEF_LEFT : MsgViewHolderType.CUSTOM_DEF_RIGHT;
				}
			}
			default:
				return in ? MsgViewHolderType.UNSUPPORT_LEFT : MsgViewHolderType.UNSUPPORT_RIGHT;
		}
		
	}
	
	public boolean hideTimeAlways() {
        switch (message.getMsgType()) {
        case notification:
            return true;
        default:
            return false;
        }
    }
}
